{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $foo == 'device_list'}class="active"{/if}><a href="{php echo $this->createWebUrl('print', array('foo' => 'device_list'));}">设备列表</a></li>
	 {if $foo == 'print_manage' && $rid}<li class="active"><a href="{php echo $this->createWebUrl('print', array('foo' => 'print_manage'));}">打印管理</a></li>{/if}
</ul>
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
</style>
{if $foo == 'device_list'}
<div class="main">
	<div style="padding:15px;">
		<table class="table table-hover table-striped">
			<thead class="navbar-inner">
				<tr>
					<th style="width:180px;">规则名称</th>
					<th>机器码</th>
					<th style="width:180px;">访问密钥</th>
					<th style="width:180px;">是否启用</th>
					<th style="width:85px; text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $devices $item}
					<tr>
						<td>{$item['rule']['rule']['name']}</td>
						<td>{$item['sn']}</td>
						<td>{$item['token']}</td>
						<td>
							{if $item['status'] == 1}
								<span class="label label-success">是</span>
							{else}
								<span class="label label-important">否</span>
							{/if}
						</td>
						<td style="text-align:right;"><a href="{php echo $this->createWebUrl('print', array('foo' => 'print_manage', 'rid' => $item['rid']));}" class="btn" title="打印管理"><i class="icon-list-alt"></i></a></td>
					</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
{elseif $foo == 'print_manage'}
<div class="main">
	<div class="stat">
		<div class="stat-div">
			<div class="navbar navbar-static-top">
				<div class="navbar-inner">
					<span class="brand">打印管理</span>
				</div>
				<div class="sub-item">
					<h4 class="sub-title">搜索</h4>
					<form action="site.php" method="get">
					<input type="hidden" name="act" value="module" />
					<input type="hidden" name="name" value="we7_photomaker" />
					<input type="hidden" name="do" value="print" />
					<input type="hidden" name="foo" value="print_manage" />
					<input type="hidden" name="rid" value="{$rid}"/>
					<table class="table sub-search">
					<tbody>
						<tr>
							<th style="width:80px;">打印状态</th>
							<td>
								<select id="status" name="status" class="span5">
									<option value="-1" {if $_GPC['status'] == -1}selected{/if}>所有记录</option>
									<option value="0" {if $_GPC['status'] == 0}selected{/if}>待打印</option>
									<option value="1" {if $_GPC['status'] == 1}selected{/if}>打印中</option>
									<option value="2" {if $_GPC['status'] == 2}selected{/if}>打印成功</option>
									<option value="3" {if $_GPC['status'] == 3}selected{/if}>打印失败</option>
								</select>
							</td>							
						</tr>
						<tr>
							<th>创建时间</th>
							<td>
								<button style="margin:0;" class="btn span5" id="date-range" type="button"><span class="date-title">{php echo date('Y-m-d', $starttime)} 至 {php echo date('Y-m-d', $endtime)}</span> <i class="icon-caret-down"></i></button>
								<input name="start" type="hidden" value="{php echo date('Y-m-d', $starttime)}" />
								<input name="end" type="hidden" value="{php echo date('Y-m-d', $endtime)}" />
							</td>
						</tr>
						<tr>
							<th></th>
							<td><input type="submit" name="" value="搜索" class="btn btn-primary"></td>
						</tr>
					</tbody>
					</table>
					</form>
				</div>
			</div>
			<div class="sub-item" id="table-list">
				<h4 class="sub-title">详细数据</h4>
				<form action="{php echo $this->createWebUrl('print');}" method="post" id="form1">
				<input type="hidden" name="log_status" id="log_status" value="2">
				<input type="hidden" name="foo" value="log_del" id="foo">
				<div class="sub-content">
					<table class="table table-hover">
						<thead class="navbar-inner">
							<tr>
								<th style="width:40px;" class="row-first">选择</th>
								<th>用户</th>
								<th>照片信息</th>
								<th>打印状态</th>
								<th>创建时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							{loop $logs $log}
							<tr>
								<td class="row-first"><input type="checkbox" name="id[]" value="{$log['id']}" /></td>
								<td style="text-align:center"><a href="#" title="{$log['openid']}">{php echo cutstr($log['openid'], 8)}</a></td>
								<td style="text-align:center"><a href="{$log['photo']}" target="_blank"><img src="{$log['photo']}" height="10" style="width:120px;"></a></td>
								<td style="text-align:center">
									{if $log['status'] == 0}
										<span class="label label-default">待打印</span>
									{elseif $log['status'] == 1}
										<span class="label label-warning">打印中</span>
									{elseif $log['status'] == 2}
										<span class="label label-success">打印成功</span>
									{elseif $log['status'] == 3}
										<span class="label label-important">打印失败</span>
									{/if}
								</td>
								<td style="font-size:12px; color:#666;text-align:center">
								{php echo date('Y-m-d H:i:s', $log[createtime]);}
								</td>
								<td style="text-align:center">
									<a href="{php echo $this->createWebUrl('print', array('id' => $log['id'], 'foo' => 'log_del'))}" class="btn" title="删除" onclick="if(!confirm('删除后将不可恢复,确定删除吗?')) return false;"><i class="icon-remove"></i></a>
								</td>
							</tr>
							{/loop}
						</tbody>
					</table>
					<table class="table">
						<tr>
							<td class="row-first">
								<input type="checkbox" id="checkall" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input type="submit" name="submit" value="删除" class="btn btn-primary" onclick="if(!confirm('删除后将不可恢复,确定删除吗?')) return false;">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<button class="btn btn-success operate" id="2">转为打印成功</button>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input type="submit" name="submit" value="转为打印失败" class="btn btn-danger operate" id="3">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input type="submit" name="submit" value="转为待打印" class="btn btn-default operate" id="0">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							</td>
						</tr>
					</table>
				</div>
					<input type="hidden" name="token" value="{$_W['token']}" />
				</form>
				{$pager}
			</div>
		</div>
	</div>
</div>
<link type="text/css" rel="stylesheet" href="./resource/style/daterangepicker.css" />
<script type="text/javascript" src="./resource/script/daterangepicker.js"></script>
<script>
$(function() {
	$('.operate').click(function(){
		var status = $(this).attr('id');
		$('#log_status').val(status);
		$('#foo').val('log_status');
		$('#form1').submit();
	});	
	
	$('#date-range').daterangepicker({
		format: 'YYYY-MM-DD',
		startDate: $(':hidden[name=start]').val(),
		endDate: $(':hidden[name=end]').val(),
		locale: {
			applyLabel: '确定',
			cancelLabel: '取消',
			fromLabel: '从',
			toLabel: '至',
			weekLabel: '周',
			customRangeLabel: '日期范围',
			daysOfWeek: moment()._lang._weekdaysMin.slice(),
			monthNames: moment()._lang._monthsShort.slice(),
			firstDay: 0
		}
	}, function(start, end){
		$('#date-range .date-title').html(start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD'));
		$(':hidden[name=start]').val(start.format('YYYY-MM-DD'));
		$(':hidden[name=end]').val(end.format('YYYY-MM-DD'));
	});
	//全选
	$('#field-all input[type="checkbox"]').change(function() {
		var a = $(this).is(':checked');
		if(a) {
			$('.field input[type="checkbox"]').each(function() {
				$(this).attr("checked", true);
			});
		} else {
			$('.field input[type="checkbox"]').each(function() {
				$(this).attr("checked", false);
			});
		}
	});
});
</script>
{/if}
{template 'common/footer'}